package com.zhenti.z1;

import java.util.HashMap;
// 来自学员看到的腾讯面试
// 测试链接 : https://leetcode.com/problems/minimum-number-of-days-to-eat-n-oranges/v
//
public class zhenti_P9 {

    public static HashMap<Integer,Integer> cache = new HashMap<>();
    public static void main(String[] args) {
        int n  = 100;

        System.out.println(MinDays(n,cache));
    }
    public static int MinDays(int  n, HashMap<Integer,Integer> cache){
        if (cache.containsKey(n)){
            return cache.get(n);
        }

        int ans = 0;
        if (n == 0){
            ans =0;
        }else if (n == 1){
            ans = 1;
        }else{
            int p1 = n %2 +1 + MinDays( n/2 ,cache);
            int p2 = n %3 +1 + MinDays( n/3 ,cache);
            ans = Math.min(p1,p2);
        }
        cache.put(n,ans);
        return ans;
    }
}
